/**
 * Copyright (c) 2021 Coder League
 * All rights reserved.
 *
 * File：OrderGoodDaoImpl.java
 * History:
 *         2021年1月27日: Initially created, Chrise.
 */
package club.coderleague.cfss.dao.impl;

import java.util.List;
import java.util.Map;

import club.coderleague.cfss.dao.extension.OrderGoodDaoExtension;
import club.coderleague.cfss.domain.beans.OrderGood;
import club.coderleague.cfss.domain.entities.Ordergoods;
import club.coderleague.cfss.domain.enums.EntityState;
import club.coderleague.cfss.domain.enums.PictureType;
import club.coderleague.data.jpa.domain.Page;
import club.coderleague.data.jpa.id.support.SnowflakeV4;
import club.coderleague.data.jpa.repository.support.AbstractDataRepositoryExtension;

/**
 * 订单商品数据访问对象实现。
 * @author Chrise
 */
public class OrderGoodDaoImpl extends AbstractDataRepositoryExtension<Ordergoods, Long, SnowflakeV4> implements OrderGoodDaoExtension {
	/**
	 * @see club.coderleague.cfss.dao.extension.OrderGoodDaoExtension#queryGoodCovers(long, java.lang.String)
	 */
	@Override
	public List<OrderGood> queryGoodCovers(long order, String goodpic) {
		String sql = "select concat('" + goodpic + "', gp.picturepath) as goodpic from " 
			+ "Goodpictures gp, Ordergoods og where gp.goodid = og.goodid and gp.entitystate = ?0 and gp.picturetype = ?1 and og.orderid = ?2";
		return super.queryCustomBeanListBySql(OrderGood.class, sql, EntityState.VALID.getValue(), PictureType.COVER.getValue(), order);
	}
	
	/**
	 * @see club.coderleague.cfss.dao.extension.OrderGoodDaoExtension#queryGoodDetails(long, java.lang.String)
	 */
	@Override
	public List<OrderGood> queryGoodDetails(long order, String goodpic) {
		String sql = "select concat('" + goodpic + "', gp.picturepath) as goodpic, og.goodname, og.goodspecs, og.goodprice, og.meteringunit, " 
			+ "og.goodnumber, og.goodtotal from Ordergoods og, Goodpictures gp " 
			+ "where gp.goodid = og.goodid and gp.entitystate = ?0 and gp.picturetype = ?1 and og.orderid = ?2";
		return super.queryCustomBeanListBySql(OrderGood.class, sql, EntityState.VALID.getValue(), PictureType.COVER.getValue(), order);
	}
	
	/**
	 * @see club.coderleague.cfss.dao.extension.OrderGoodDaoExtension#queryGoodListData(java.lang.Long, java.lang.Integer, java.lang.Integer)
	 */
	@Override
	public Page<Map<String, Object>> queryGoodListData(Long orderid, Integer pageIndex, Integer pageSize) {
		String csql = "select count(g.entityid) from Goods g, Ordergoods og where g.entityid = og.goodid and og.orderid = ?0";
		String qsql = "select g.entityid, og.goodname, g.manufacturer, og.goodspecs, og.goodnumber, og.meteringunit, og.goodtotal " 
			+ "from Goods g, Ordergoods og where g.entityid = og.goodid and og.orderid = ?0 order by og.entityid";
		return super.queryMapPageBySql(csql, qsql, pageIndex, pageSize, orderid);
	}
}
